package edu.hwadee.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ModelDriven;

import edu.hwadee.entity.Staff;

/**
 * ClassName: StafflAction
 * 
 * @Description: 锟斤拷锟斤拷为锟斤拷员锟斤拷息锟斤拷锟紸ction锟洁，锟斤拷锟节癸拷锟斤拷锟斤拷锟绞伙拷锟斤拷锟斤拷息锟斤拷锟斤拷删锟斤拷牟锟斤拷锟斤拷锟轿拷锟皆憋拷锟较拷锟斤拷锟侥ｏ拷锟�
 *               只锟斤拷系统锟斤拷锟斤拷员锟斤拷锟杰诧拷锟斤拷
 * @author chenjianhao
 * @date 2018锟斤拷8锟斤拷14锟斤拷
 */
public class StaffAction extends BasicAction implements ModelDriven<Staff> {

	private static final long serialVersionUID = 1L;
	private Staff staff;
	private int staffComplementId;

	
	public String showAll()
	{
		return null;
	}


	@Override
	public Staff getModel() {
		if (staff == null)
			staff = new Staff();
		return staff;
	}


	public String addStaff() {
		if (staff != null) {
			boolean success = getStaffServiceImpl().save(staff);
			if (success)
				return "success";
		}
		return "fail";
	}

	public String deleteStaff() {
		if (staff != null) {
			boolean success = getStaffServiceImpl().delete(staff);
			if (success)
				return "success";
		}
		return "fail";
	}

	public String updateStaff() {
		if (staff != null) {
			boolean success = getStaffServiceImpl().update(staff);
			if (success)
				return "success";
		}
		return "fail";
	}

	public void searchStaff(Staff staff) {
		/*
		 * try { if(staff != null){List<Staff> s =
		 * getStaffServiceImpl().search(staff);} } catch(Exception ex) { return
		 * "fail"; } return "success";
		 */
		this.staff = staff;
	}

	public Staff getStaff() {
		return staff;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}



	public String searchById(Integer staffId) {

		if (staff.getStaffId() == staffId)
			return "success";
		else
			return "fail";
	}

	public String showStaff() {
		List<Staff> list = getStaffServiceImpl().showAll();
		ServletActionContext.getContext().getSession().put("allstaff", list);
		return "success";
	}

	

	/*
	 * public void deleteStaff(Staff staff) { delete }
	 */

	public int getStaffComplementId() {
		return staffComplementId;
	}

	public void setStaffComplementId(int staffComplementId) {
		this.staffComplementId = staffComplementId;
	}



}
